#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include<QToolBar>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //创建菜单栏
    QMenuBar*mebubar =this->menuBar();
    this->setMenuBar(mebubar);

    //创建菜单
    QMenu *menu =new QMenu("文件");
    mebubar->addMenu(menu);

    //工具兰手动创建出来的，自动不会创建出来
    QToolBar* toolbar = new QToolBar();
    this->addToolBar(toolbar);

    //创建两个菜单项
    QAction*action1 = new QAction("保存");
    QAction*action2 = new QAction("打开");
    action1->setToolTip("点击这里保存文件");
    action2->setToolTip("低级这里打开文件");


    //菜单放到菜单中
    menu->addAction(action1);
    menu->addAction(action2);
   //菜单放到工具栏中
    toolbar->addAction(action1);
    action1->setIcon(QIcon(":/Payara.png"));
    toolbar->addAction(action2);
    action2->setIcon(QIcon(":/Payara.png"));

    connect(action1,&QAction::triggered,this,&MainWindow::handl1);
    connect(action2,&QAction::triggered,this,&MainWindow::handl2);

}

MainWindow::~MainWindow()
{
    delete ui;

}

void MainWindow::handl1()
{
    qDebug()<<"handl1";
}

void MainWindow::handl2()
{
    qDebug()<<"handl2";
}

